{include file="common/head"}
<head>
<title>商品列表</title>

<style>
.form-control{width: initial;display: inline-block;}
</style>
</head>
<body >
<div class="container-fluid">

    <form action="/index.php/goods/index" method="post">
    <div class="row" id="query_bar" style="height: 50px;line-height: 50px;">
        <div class="col">

        <label for="cat_id" >类别:
          <select id="cat_id" name="cat_id" class="form-control">
              {foreach $cats as $k=>$v}
                <option value="{$k}" {if $v['deepth']==1} style="font-size:1.1rem;color:#007;" {/if} {if $cat_id==$k }selected{/if}>
                    {if $v['deepth']==1}
                        ├─
                    {elseif $v['deepth']==2}
                        &nbsp;&nbsp;&nbsp;&nbsp;├─
                    {elseif $v['deepth']==3}
                        &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├─
                    {/if}
                    {$v['name']}
                </option>
              {/foreach}
          </select>

        </label>

        <label for="status" >状态:
            <select id="status" name="status" class="form-control">
                <option value="">全部</option>
                {foreach $status_arr as $k=>$v}
                    <option value="{$k}" {if $k==$status} selected {/if} >{$v}</option>
                {/foreach}
            </select>
        </label>
  

        <label for="name" >关键字：
            <input class="form-control" type="text" value="{$name}" id="name" name="name" placeholder="名称关键字" />
        </label>

        
        <button type="button" class="btn btn-warning query" style="vertical-align: middle;" >
            <span class="bi-search" ></span>
        </button>

    
        </div>

    </div>
    </form>

    <h2>商品管理</h2>
    <table class="table table-sm table-hover table-striped" style="width: 100%;">
        <thead style="">
            <th>序号</th>
            <th>名称</th>
            <th>类别</th>
            <th>商家</th>
            <th>最低价</th>
            <th>最高价</th>
            <th>规格</th>
            <th>图片</th>
            <th>收藏数</th>
            <th>录入人</th>        
            <th>录入时间</th>
            <th>上架</th>
            <th >
                <a href="/index.php/goods/goods_add" alt="新增商品(New goods)" style="color:white;">
                <button type="button" class="btn btn-sm btn-primary" >
                    <span class="bi-plus-lg"></span>
                </button></a>                
            </th>
        </thead>
        <tbody>
            {foreach $list['data'] as $k=>$kv}
            <tr>
                <td>{$k+1}</td>
                <td class="long_field">
                    {if $kv['status']!=1}<span style="background:red;color:white;padding: 0 3px;">下架!</span>{/if}
                    {$kv['name']}
                    {if $kv['hot']==1}<span class="bi-lightning-charge-fill" style="color:red;"></span>{/if}
                </td>
                <td>{$kv['cat_id_name']}</td>
                <td>{$kv['dept_id_name']}</td>
                <td><c>{$kv['price']}</c></td>
                <td><c>{$kv['price1']}</c></td>
                <td>
                    {foreach $kv['specs'] as $sp}
                    
                        {if $sp['status']==1 }
                        <a href = "/index.php/goods/spec_edit/id/{$sp['id']}">
                            <button class="btn btn-sm btn-outline-primary" style="margin:2px;max-width: 100px;overflow-x: hidden;" >{$sp['name']}</button>
                        </a>
                        {else}
                        <a href = "/index.php/goods/spec_edit/id/{$sp['id']}">
                            <button class="btn btn-sm btn-outline-dark" style="margin:2px;text-decoration:line-through;" >{$sp['name']}</button>
                        </a>

                        <button class="btn btn-sm btn-danger spec_del" spec_id="{$sp['id']}" style="margin-left:-10px;" name="{$sp['name']}">
                            <span class="bi-x"></span>
                        </button>

                        {/if}
                            
                            
                    
                    {/foreach}
                    <a href = "/index.php/goods/spec_add/goods_id/{$kv['id']}">
                        <button class="btn btn-sm btn-info"><span class="bi-plus"></span></button>
                    </a>
                </td>
                <td style="width:300px;">
                    {foreach $kv['image'] as $image}
                        <img class="goods_image" src="{$image}" style="width:40px;border:1px solid #ccc;" />
                    {/foreach}
                </td>
                <td>{$kv['fav_count']}</td>
                <td>{$kv['creater_name']}</td>
                <td>{$kv['create_time']|date='Y-m-d H:i:s'}</td>
                <td {if $kv.status!=1} style="text-decoration:line-through;color:red;" {/if} >{$kv['status_name']}</td>
                <td >
                    <a href="/index.php/goods/edit/id/{$kv['id']}">
                        <button tyle="button" class="btn btn-sm btn-info"><span class="bi-pencil"></span></button>
                    </a>
                    {if $kv['status']==2}
                        <button type="button" class="btn btn-sm btn-danger goods_del" goods_id="{$kv['id']}" name="{$kv['name']}">
                            <span class="bi-trash"></span>
                        </button>
                    {/if}
                </td>
            </tr>
            {/foreach}
        
        </tbody>    
    </table>
    {include file="common/pagination"}
</div>

</body>

<script type="text/javascript">
  $(document).ready(function(){    

    $(".query").on('click',function(){
        var index = layer.load(0, {shade: false}); //0代表加载的风格，支持0-2
        var cid = $("#customer_id").val();
        var order_no = $("#order_no").val();
        var sdate = $("#sdate").val();
        var edate = $("#edate").val();

        $("form").submit();
        layer.close(index);
    })

    $(".goods_image").on('click',function(){
        var img = $(this).attr('src');
        if(!img.trim()) return;

        layer.open({
          type: 1,
          offset:['10px','10px'],
          title:'',
          closeBtn: 0, //不显示关闭按钮
          anim: 1,
          time: 5*1000,
          shadeClose: true, //开启遮罩关闭              
          skin: 'layui-layer-rim', 
          content: "<img src='"+img+"' style='width:100%'>"
        });
    })

    $('.goods_del,.spec_del').on('click',function(){
        var sp_id=$(this).attr('spec_id');
        var goods_id=$(this).attr('goods_id');
        var name=$(this).attr('name');

        if(sp_id){
            var method='spec_del';
            var data={id:sp_id};
            //询问框
        }else if(goods_id){
            var method='goods_del';
            data={id:goods_id};
        }

        layer.confirm('是否确定删除项目['+name+']?', {
          btn: ['确定删除','再检查一下'] //按钮
        }, function(){

            $.ajax({
                url:'/index.php/goods/'+method,
                type:'post',
                data:data,
                success:function(res){
                    if(res.code){
                        layer.msg('删除成功!');
                        location.reload();
                    }else{
                        layer.msg(res.msg);
                    }
                     
                },
                fail:function(res){
                    layer.msg(res.code+'failed!');
                }
            });

            e.preventDefault(); 
            
        }, function(){
            layer.msg('操作取消！');
            return false;
            e.preventDefault(); //阻止冒泡
        }); 


    })
})
</script>


</body>
</html>
